home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / demo / wemdemo4.zip / INFO / ELISP.3 < prev    next >
Text File  |  1994-09-21  |  50KB  |  1,334 lines

  1. Info file elisp, produced by Makeinfo, -*- Text -*- from input file
  2. elisp.texi.
  3.  
  4.    This file documents GNU Emacs Lisp.
  5.  
  6.    This is edition 1.03 of the GNU Emacs Lisp Reference Manual,   for
  7. Emacs Version 18.
  8.  
  9.    Published by the Free Software Foundation, 675 Massachusetts
  10. Avenue,  Cambridge, MA 02139 USA
  11.  
  12.    Copyright (C) 1990 Free Software Foundation, Inc.
  13.  
  14.    Permission is granted to make and distribute verbatim copies of
  15. this manual provided the copyright notice and this permission notice
  16. are preserved on all copies.
  17.  
  18.    Permission is granted to copy and distribute modified versions of
  19. this manual under the conditions for verbatim copying, provided that
  20. the entire resulting derived work is distributed under the terms of a
  21. permission notice identical to this one.
  22.  
  23.    Permission is granted to copy and distribute translations of this
  24. manual into another language, under the above conditions for modified
  25. versions, except that this permission notice may be stated in a
  26. translation approved by the Foundation.
  27.  
  28.  
  29. 
  30. File: elisp,  Node: Stream Type,  Next: Keymap Type,  Prev: Process Type,  Up: Editing Types
  31.  
  32. Stream Type
  33. -----------
  34.  
  35.    A "stream" is an object that can be used as a source or sink for
  36. characters--either to supply characters for input or to accept them
  37. as output.  Many different types can be used this way: markers,
  38. buffers, strings, and functions.  Most often, input streams
  39. (character sources) obtain characters from the keyboard, a buffer, or
  40. a file, and output streams (character sinks) send characters to a
  41. buffer, such as a `*Help*' buffer, or to the echo area.
  42.  
  43.    The object `nil', in addition to its other meanings, may be used
  44. as a stream.  It stands for the value of the variable
  45. `standard-input' or `standard-output'.  Also, the object `t' as a
  46. stream specifies input using the minibuffer (*note Minibuffers::.) or
  47. output in the echo area (*note The Echo Area::.).
  48.  
  49.    Streams have no special printed representation or read syntax, and
  50. print as whatever primitive type they are.
  51.  
  52.    *Note Streams::, for a description of various functions related to
  53. streams, including various parsing and printing functions.
  54.  
  55.  
  56. 
  57. File: elisp,  Node: Keymap Type,  Next: Syntax Table Type,  Prev: Stream Type,  Up: Editing Types
  58.  
  59. Keymap Type
  60. -----------
  61.  
  62.    A "keymap" maps keys typed by the user to functions.  This mapping
  63. controls how the user's command input is executed.  Emacs defines two
  64. kinds of keymaps: "full keymaps", which are vectors of 128 elements,
  65. and "sparse keymaps", which are association lists whose first element
  66. is the symbol `keymap'.
  67.  
  68.    *Note Keymaps::, for information about creating keymaps, handling
  69. prefix keys, local as well as global keymaps, and changing key
  70. bindings.
  71.  
  72.  
  73. 
  74. File: elisp,  Node: Syntax Table Type,  Prev: Keymap Type,  Up: Editing Types
  75.  
  76. Syntax Table Type
  77. -----------------
  78.  
  79.    A "syntax table" is a vector of 256 integers.  Each element of the
  80. vector defines how one character is interpreted when it appears in a
  81. buffer.  For example, in C mode (*note Major Modes::.), the `+'
  82. character is punctuation, but in Lisp mode it is a valid character in
  83. a symbol.  These different interpretations are effected by changing
  84. the syntax table entry for `+', i.e., at index 43.
  85.  
  86.    Syntax tables are only used for scanning text in buffers, not for
  87. reading Lisp expressions.  The table the Lisp interpreter uses to
  88. read expressions is built into the Emacs source code and cannot be
  89. changed; thus, to change the list delimiters to be `{' and `}'
  90. instead of `(' and `)' would be impossible.
  91.  
  92.    *Note Syntax Tables::, for details about syntax classes and how to
  93. make and modify syntax tables.
  94.  
  95.  
  96. 
  97. File: elisp,  Node: Type Predicates,  Next: Equality Predicates,  Prev: Editing Types,  Up: Types of Lisp Object
  98.  
  99. Type Predicates
  100. ===============
  101.  
  102.    The Emacs Lisp interpreter itself does not perform type checking
  103. on the actual arguments passed to functions when they are called.  It
  104. could not do otherwise, since variables in Lisp are not declared to
  105. be of a certain type, as they are in other programming languages.  It
  106. is therefore up to the individual function to test whether each
  107. actual argument belongs to a type that can be used by the function.
  108.  
  109.    All built-in functions do check the types of their actual
  110. arguments when appropriate and signal a `wrong-type-argument' error
  111. if an argument is of the wrong type.  For example, here is what
  112. happens if you pass an argument to `+' which it cannot handle:
  113.  
  114.      (+ 2 'a)
  115.           error--> Wrong type argument: integer-or-marker-p, a
  116.  
  117.    Many functions, called "type predicates", are provided to test
  118. whether an object is a member of a given type.  (Following a
  119. convention of long standing, the names of most Emacs Lisp predicates
  120. end in `p'.)
  121.  
  122.    Here is a table of predefined type predicates, in alphabetical
  123. order, with references to further information.
  124.  
  125. `atom'
  126.      *note atom: List-related Predicates.
  127.  
  128. `arrayp'
  129.      *note arrayp: Array Functions.
  130.  
  131. `bufferp'
  132.      *note bufferp: Buffer Basics.
  133.  
  134. `char-or-string-p'
  135.      *note char-or-string-p: Predicates for Strings.
  136.  
  137. `consp'
  138.      *note consp: List-related Predicates.
  139.  
  140. `integer-or-marker-p'
  141.      *note integer-or-marker-p: Predicates on Markers.
  142.  
  143. `integerp'
  144.      *note integerp: Predicates on Numbers.
  145.  
  146. `keymapp'
  147.      *note keymapp: Creating Keymaps.
  148.  
  149. `listp'
  150.      *note listp: List-related Predicates.
  151.  
  152. `markerp'
  153.      *note markerp: Predicates on Markers.
  154.  
  155. `natnump'
  156.      *note natnump: Predicates on Numbers.
  157.  
  158. `nlistp'
  159.      *note nlistp: List-related Predicates.
  160.  
  161. `processp'
  162.      *note processp: Processes.
  163.  
  164. `sequencep'
  165.      *note sequencep: Sequence Functions.
  166.  
  167. `stringp'
  168.      *note stringp: Predicates for Strings.
  169.  
  170. `subrp'
  171.      *note subrp: Function Cells.
  172.  
  173. `symbolp'
  174.      *note symbolp: Symbols.
  175.  
  176. `syntax-table-p'
  177.      *note syntax-table-p: Syntax Tables.
  178.  
  179. `user-variable-p'
  180.      *note user-variable-p: Defining Variables.
  181.  
  182. `vectorp'
  183.      *note vectorp: Vectors.
  184.  
  185. `windowp'
  186.      *note windowp: Basic Windows.
  187.  
  188.  
  189. 
  190. File: elisp,  Node: Equality Predicates,  Prev: Type Predicates,  Up: Types of Lisp Object
  191.  
  192. Equality Predicates
  193. ===================
  194.  
  195.    Here we describe two functions that test for equality between any
  196. two objects.  Other functions test equality between objects of
  197. specific types, e.g., strings.  See the appropriate chapter
  198. describing the data type for these predicates.
  199.  
  200.  * Function: eq OBJECT1 OBJECT2
  201.      This function returns `t' if OBJECT1 and OBJECT2 are the same
  202.      object, `nil' otherwise.  The "same object" means that a change
  203.      in one will be reflected by the same change in the other.
  204.  
  205.      `eq' will be true if OBJECT1 and OBJECT2 are numbers with the
  206.      same value.  Also, since symbol names are normally unique, if
  207.      the arguments are symbols with the same name, they are `eq'. 
  208.      For other types (e.g., lists, vectors, strings), two arguments
  209.      with the same contents or elements are not necessarily `eq' to
  210.      each other: they are `eq' only if they are the same object.
  211.  
  212.      (The `make-symbol' function returns an uninterned symbol that is
  213.      not interned in the standard `obarray'.  When uninterned symbols
  214.      are in use, symbol names are no longer unique.  Distinct symbols
  215.      with the same name are not `eq'.  *Note Creating Symbols::.)
  216.  
  217.           (eq 'foo 'foo)
  218.                => t
  219.           
  220.           (eq 456 456)
  221.                => t
  222.           
  223.           (eq "asdf" "asdf")
  224.                => nil
  225.           
  226.           (eq '(1 (2 (3))) '(1 (2 (3))))
  227.                => nil
  228.           
  229.           (eq [(1 2) 3] [(1 2) 3])
  230.                => nil
  231.           
  232.           (eq (point-marker) (point-marker))
  233.                => nil
  234.  
  235.  * Function: equal OBJECT1 OBJECT2
  236.      This function returns `t' if OBJECT1 and OBJECT2 have equal
  237.      components, `nil' otherwise.  Whereas `eq' tests if its
  238.      arguments are the same object, `equal' looks inside nonidentical
  239.      arguments to see if their elements are the same.  So, if two
  240.      objects are `eq', they are `equal', but the converse is not
  241.      always true.
  242.  
  243.           (equal 'foo 'foo)
  244.                => t
  245.           
  246.           (equal 456 456)
  247.                => t
  248.           
  249.           (equal "asdf" "asdf")
  250.                => t
  251.           (eq "asdf" "asdf")
  252.                => nil
  253.           
  254.           (equal '(1 (2 (3))) '(1 (2 (3))))
  255.                => t
  256.           (eq '(1 (2 (3))) '(1 (2 (3))))
  257.                => nil
  258.           
  259.           (equal [(1 2) 3] [(1 2) 3])
  260.                => t
  261.           (eq [(1 2) 3] [(1 2) 3])
  262.                => nil
  263.           
  264.           (equal (point-marker) (point-marker))
  265.                => t
  266.  
  267.              (eq (point-marker) (point-marker))
  268.                => nil
  269.  
  270.      Comparison of strings is case-sensitive.
  271.  
  272.           (equal "asdf" "ASDF")
  273.                => nil
  274.  
  275.    The test for equality is implemented recursively, and circular
  276. lists may therefore cause infinite recursion (leading to an error).
  277.  
  278.  
  279. 
  280. File: elisp,  Node: Numbers,  Next: Strings and Characters,  Prev: Types of Lisp Object,  Up: Top
  281.  
  282. Numbers
  283. *******
  284.  
  285.    Integers are the only kind of number in version 18 Emacs Lisp. 
  286. These are whole numbers such as -3, 0, 7, 13, and 511.
  287.  
  288.    In version 19, there is a compile time option to support floating
  289. point numbers, which are represented internally as the C type `double'.
  290. A floating point number is a number with a fractional part, such as
  291. -4.5, 0.0, or 2.71828.  A floating point number can be expressed in
  292. an exponential notation as well: thus, 1.5e2 equals 150; in this
  293. example, `e2' stands for ten to the second power, and is multiplied
  294. by 1.5.
  295.  
  296. * Menu:
  297.  
  298. * Number Basics::             Representation and range of numbers.
  299. * Predicates on Numbers::     Testing for numbers.
  300. * Comparison of Numbers::     Equality and inequality predicates.
  301. * Arithmetic Operations::     How to add, subtract, multiply and divide.
  302. * Bitwise Operations::        Logical and, or, not, shifting.
  303. * Random Numbers::            Obtaining random integers, predictable or not.
  304.  
  305.  
  306. 
  307. File: elisp,  Node: Number Basics,  Next: Predicates on Numbers,  Prev: Numbers,  Up: Numbers
  308.  
  309. Number Basics
  310. =============
  311.  
  312.    The range of values for an integer depends on the machine.  The
  313. range is -8388608 to 8388607 (24 bits; i.e.,
  314.  
  315.    -2**23
  316.  
  317.    to
  318.  
  319.    2**23 - 1
  320.  
  321.    ) on most machines, but on others it is -16777216 to 16777215 (25
  322. bits), or -33554432 to 33554431 (26 bits).  All of the examples shown
  323. below assume an integer has 24 bits.
  324.  
  325.    The Lisp reader reads numbers as a sequence of digits with an
  326. optional sign.
  327.  
  328.      1                ; The integer 1.
  329.      +1               ; Also the integer 1.
  330.      -1               ; The integer -1.
  331.      16777217         ; Also the integer 1, due to overflow.
  332.      0                ; The number 0.
  333.      -0               ; The number 0.
  334.      1.               ; Invalid syntax.
  335.  
  336.     To understand how various functions work on integers, especially
  337. the bitwise operators (*note Bitwise Operations::.), it is often
  338. helpful to view the numbers in their binary form.
  339.  
  340.    In 24 bit binary, the decimal integer 5 looks like this:
  341.  
  342.      0000 0000  0000 0000  0000 0101
  343.  
  344. (We have inserted spaces between groups of 4 bits, and two spaces
  345. between groups of 8 bits, to make the binary integer easier to read.)
  346.  
  347.    The integer -1 looks like this:
  348.  
  349.      1111 1111  1111 1111  1111 1111
  350.  
  351. -1 is represented as 24 ones.  (This is called "two's complement"
  352. notation.)
  353.  
  354.    The negative integer, -5, is creating by subtracting 4 from -1. 
  355. In binary, the decimal integer 4 is 100.  Consequently, -5 looks like
  356. this:
  357.  
  358.      1111 1111  1111 1111  1111 1011
  359.  
  360.    In this implementation, the largest 24 bit binary integer is the
  361. decimal integer 8,388,607.  In binary, this number looks like this:
  362.  
  363.      0111 1111  1111 1111  1111 1111
  364.  
  365.    Since the arithmetic functions do not check whether integers go
  366. outside their range, when you add 1 to 8,388,607, the value is
  367. negative integer -8,388,608:
  368.  
  369.      (+ 1 8388607)
  370.           => -8388608
  371.           => 1000 0000  0000 0000  0000 0000
  372.  
  373.    Many of the following functions accept markers for arguments as
  374. well as integers.  (*Note Markers::.)  More precisely, the actual
  375. parameters to such functions may be either integers or markers, which
  376. is why we often give these parameters the name MARKER-OR-INT.  When
  377. the actual parameter is a marker, the position value of the marker is
  378. used and the buffer of the marker is ignored.
  379.  
  380.  
  381. 
  382. File: elisp,  Node: Predicates on Numbers,  Next: Comparison of Numbers,  Prev: Number Basics,  Up: Numbers
  383.  
  384. Type Predicates for Numbers
  385. ===========================
  386.  
  387.    The functions in this section test whether the argument is a
  388. number or whether it is a certain sort of number.  `integerp' and
  389. `natnump' can take any type of Lisp object as argument (the
  390. predicates would not be of much use otherwise); but the `zerop'
  391. predicate requires an integer as its argument.
  392.  
  393.  * Function: integerp OBJECT
  394.      This predicate tests whether its argument is an integer (a whole
  395.      number) and returns `t' if so, `nil' otherwise.
  396.  
  397.  * Function: natnump OBJECT
  398.      The `natnump' predicate (whose name comes from the phrase
  399.      "natural-number-p") tests to see whether its argument is a
  400.      nonnegative integer, and returns `t' if so, `nil' otherwise.  0
  401.      is considered non-negative.
  402.  
  403.      Markers are not converted to integers, hence `natnump' of a
  404.      marker is always `nil'.
  405.  
  406.      People have pointed out that this function is misnamed, because
  407.      the term "natural number" is usually understood as excluding
  408.      zero.  We are open to suggestions for a better name to use in
  409.      version 19.
  410.  
  411.  * Function: zerop INTEGER
  412.      This predicate tests whether its argument is zero, and returns
  413.      `t' if so, `nil' otherwise.  These two forms are equivalent:
  414.      `(zerop x) == (= x 0)'.
  415.  
  416.  
  417. 
  418. File: elisp,  Node: Comparison of Numbers,  Next: Arithmetic Operations,  Prev: Predicates on Numbers,  Up: Numbers
  419.  
  420. Comparison of Numbers
  421. =====================
  422.  
  423.    The integer type is implemented by storing the value in the
  424. "pointer part" of a Lisp object (which, on typical target machines,
  425. has 24 bits of pointer, 7 bits of type and 1 bit for the garbage
  426. collector).  Because of this, the function `eq' will return `t' for
  427. two integers with the same value.  *Note Equality Predicates::.
  428.  
  429.      Common Lisp note: because of the way numbers are implemented in
  430.      Common Lisp, you generally need to use ``='' to test for
  431.      equality between numbers.  However, GNU Emacs Lisp does not need
  432.      very large integers; as a consequence, it is possible to
  433.      restrict them to the size of a single word, allowing `eq' to be
  434.      used.
  435.  
  436.  * Function: = MARKER-OR-INT1 MARKER-OR-INT2
  437.      This function tests whether its arguments are the same number,
  438.      and returns `t' if so, `nil' otherwise.
  439.  
  440.  * Function: /= MARKER-OR-INT1 MARKER-OR-INT2
  441.      This function tests whether its arguments are not the same
  442.      number, and returns `t' if so, `nil' otherwise.
  443.  
  444.  * Function: < MARKER-OR-INT1 MARKER-OR-INT2
  445.      This function tests whether its first argument is strictly less
  446.      than its second argument.  It returns `t' if so, `nil' otherwise.
  447.  
  448.  * Function: <= MARKER-OR-INT1 MARKER-OR-INT2
  449.      This function tests whether its first argument is less than or
  450.      equal to its second argument.  It returns `t' if so, `nil'
  451.      otherwise.
  452.  
  453.  * Function: > MARKER-OR-INT1 MARKER-OR-INT2
  454.      This function tests whether its first argument is strictly
  455.      greater than its second argument.  It returns `t' if so, `nil'
  456.      otherwise.
  457.  
  458.  * Function: >= MARKER-OR-INT1 MARKER-OR-INT2
  459.      This function tests whether its first argument is greater than
  460.      or equal to its second argument.  It returns `t' if so, `nil'
  461.      otherwise.
  462.  
  463.  * Function: max MARKER-OR-INT &rest MARKERS-OR-INTS
  464.      This function returns the largest of its arguments.
  465.  
  466.           (max 20)
  467.                => 20
  468.           (max 1 2)
  469.                => 2
  470.           (max 1 3 2)
  471.                => 3
  472.  
  473.  * Function: min MARKER-OR-INT &rest MARKERS-OR-INTS
  474.      This function returns the smallest of its arguments.
  475.  
  476.  
  477. 
  478. File: elisp,  Node: Arithmetic Operations,  Next: Bitwise Operations,  Prev: Comparison of Numbers,  Up: Numbers
  479.  
  480. Arithmetic Operations
  481. =====================
  482.  
  483.    Emacs Lisp provides the traditional four arithmetic operations:
  484. addition, subtraction, multiplication, and division.  A remainder
  485. function supplements the (integer) division function.  In addition,
  486. as a convenience, incrementing and decrementing functions are provided.
  487.  
  488.    It is important to note that in GNU Emacs Lisp, arithmetic
  489. functions do not check for overflow.  Thus `(1+ 8388607)' may equal
  490. -8388608, depending on your hardware.
  491.  
  492.  * Function: 1+ MARKER-OR-INT
  493.      This function adds one to MARKER-OR-INT.
  494.  
  495.  * Function: 1- MARKER-OR-INT
  496.      This function subtracts one from MARKER-OR-INT.
  497.  
  498.  * Function: + &rest MARKERS-OR-INTS
  499.      This function adds its arguments together.  When given no
  500.      arguments, `+' returns 0.  It does not check for overflow.
  501.  
  502.           (+)
  503.                => 0
  504.           (+ 1)
  505.                => 1
  506.           (+ 1 2 3 4)
  507.                => 10
  508.  
  509.  * Function: - &optional MARKER-OR-INT &rest OTHER-MARKERS-OR-INTS
  510.      The `-' function serves two purposes: negation and subtraction. 
  511.      When `-' has a single argument, the value is the negative of the
  512.      argument.  When there are multiple arguments, each of the
  513.      OTHER-MARKERS-OR-INTS is subtracted from MARKER-OR-INT,
  514.      cumulatively.  If there are no arguments, the result is 0.  This
  515.      function does not check for overflow.
  516.  
  517.           (- 10 1 2 3 4)
  518.                => 0
  519.           (- 10)
  520.                => -10
  521.           (-)
  522.                => 0
  523.  
  524.  * Function: * &rest MARKERS-OR-INTEGERS
  525.      This function multiplies its arguments together, and returns the
  526.      product.  When given no arguments, `*' returns 1.  It does not
  527.      check for overflow.
  528.  
  529.           (*)
  530.                => 1
  531.           (* 1)
  532.                => 1
  533.           (* 1 2 3 4)
  534.                => 24
  535.  
  536.  * Function: / DIVIDEND DIVISOR &rest DIVISORS
  537.      This function divides DIVIDEND by DIVISORS and returns the
  538.      quotient.  If there are additional arguments DIVISORS, then
  539.      DIVIDEND is divided by each divisor in turn.    Each argument
  540.      may be an integer or a marker.
  541.  
  542.      The result is normally rounded towars zero after each division,
  543.      but some machines may round differently with negative arguments.
  544.      This is because the Lisp function `/' is implemented using the C
  545.      division operator, which has the same possibility for
  546.      machine-dependent rounding.  In practice, all known machines
  547.      round in the standard fashion.
  548.  
  549.      If you divide by 0, an `arith-error' error is signaled.  (*Note
  550.      Errors::.)
  551.  
  552.           (/ 6 2)
  553.                => 3
  554.           (/ 5 2)
  555.                => 2
  556.           (/ 25 3 2)
  557.                => 4
  558.           (/ -17 6)
  559.                => -2          ; (Could be -3 on some machines.)
  560.  
  561.  * Function: % DIVIDEND DIVISOR
  562.      This function returns the value of DIVIDEND modulo DIVISOR; in
  563.      other words, the integer remainder after division of DIVIDEND by
  564.      DIVISOR.  The sign of the result is the sign of DIVIDEND.  The
  565.      sign of DIVISOR is ignored.  The arguments must be integers.
  566.  
  567.      For negative arguments, the value is in principle
  568.      machine-dependent since the quotient is; but in practice, all
  569.      known machines behave alike.
  570.  
  571.      An `arith-error' results if DIVISOR is 0.
  572.  
  573.           (% 9 4)
  574.                => 1
  575.           (% -9 4)
  576.                => -1
  577.           (% 9 -4)
  578.                => 1
  579.           (% -9 -4)
  580.                => -1
  581.  
  582.      For any two numbers DIVIDEND and DIVISOR,
  583.  
  584.           (+ (% DIVIDEND DIVISOR)
  585.              (* (/ DIVIDEND DIVISOR) DIVISOR))
  586.  
  587.      always equals DIVIDEND.
  588.  
  589.  
  590. 
  591. File: elisp,  Node: Bitwise Operations,  Next: Random Numbers,  Prev: Arithmetic Operations,  Up: Numbers
  592.  
  593. Bitwise Operations on Integers
  594. ==============================
  595.  
  596.    In a computer, an integer is represented as a binary number, a
  597. sequence of "bits" (digits which are either zero or one).  A bitwise
  598. operation acts on the individual bits of such a sequence.  For
  599. example, "shifting" moves the whole sequence left or right one or
  600. more places, reproducing the same pattern "moved over".
  601.  
  602.    The bitwise operations in Emacs Lisp apply only to integers.
  603.  
  604.  * Function: lsh INTEGER1 COUNT
  605.      `lsh', which is an abbreviation for "logical shift", shifts the
  606.      bits in INTEGER1 to the left COUNT places, or to the right if
  607.      COUNT is negative.  If COUNT is negative, `lsh' shifts zeros
  608.      into the most-significant bit, producing a positive result even
  609.      if INTEGER1 is negative.  Contrast this with `ash', below.
  610.  
  611.      Thus, the decimal number 5 is the binary number 00000101. 
  612.      Shifted once to the left, with a zero put in the one's place,
  613.      the number becomes 00001010, decimal 10.
  614.  
  615.      Here are two examples of shifting the pattern of bits one place
  616.      to the left.  Since the contents of the rightmost place has been
  617.      moved one place to the left, a value has to be inserted into the
  618.      rightmost place.  With `lsh', a zero is placed into the
  619.      rightmost place.  (These examples show only the low-order eight
  620.      bits of the binary pattern; the rest are all zero.)
  621.  
  622.           (lsh 5 1)
  623.                => 10
  624.           
  625.           00000101 => 00001010     ; Decimal 5 becomes decimal 10.
  626.           
  627.           (lsh 7 1)
  628.                => 14
  629.           
  630.           00000111 => 00001110     ; Decimal 7 becomes decimal 14.
  631.  
  632.       As the examples illustrate, shifting the pattern of bits one
  633.      place to the left produces a number that is twice the value of
  634.      the previous number.
  635.  
  636.      Note, however that functions do not check for overflow, and a
  637.      returned value may be negative (and in any case, no more than a
  638.      24 bit value) when an integer is sufficiently left shifted.  For
  639.      example:
  640.  
  641.           (lsh 8388607 1)          ; left shift
  642.                => -2
  643.  
  644.      In binary, in the 24 bit implementation,
  645.  
  646.           0111 1111  1111 1111  1111 1111         ; Decimal 8,388,607
  647.  
  648.      becomes
  649.  
  650.           1111 1111  1111 1111  1111 1110         ; Decimal -2
  651.  
  652.      Shifting the pattern of bits two places to the left produces
  653.      results like this (with 8-bit binary numbers):
  654.  
  655.           (lsh 3 2)
  656.                => 12
  657.           
  658.           00000011 => 00001100       ; Decimal 3 becomes decimal 12.
  659.  
  660.       On the other hand, shifting the pattern of bits one place to the
  661.      right looks like this:
  662.  
  663.           (lsh 6 -1)
  664.                => 3
  665.           
  666.           00000110 => 00000011       ; Decimal 6 becomes decimal 3.
  667.           
  668.           (lsh 5 -1)
  669.                => 2
  670.           
  671.           00000101 => 00000010       ; Decimal 5 becomes decimal 2.
  672.  
  673.       As the example illustrates, shifting the pattern of bits one
  674.      place to the right divides the value of the binary number by
  675.      two, rounding downward.
  676.  
  677.  * Function: ash INTEGER1 COUNT
  678.      `ash' ("arithmetic shift") shifts the bits in INTEGER1 to the
  679.      left COUNT places, or to the right if COUNT is negative.
  680.  
  681.      `ash' gives the same results as `lsh' except when INTEGER1 and
  682.      COUNT are both negative.  In that case, `ash' puts a one in the
  683.      leftmost position, while `lsh' puts a zero in the leftmost
  684.      position.
  685.  
  686.      Thus, with `ash', shifting the pattern of bits one place to the
  687.      right looks like this:
  688.  
  689.           (ash -6 -1)
  690.                => -3            ; Decimal -6 becomes decimal -3.
  691.           
  692.           1111 1111  1111 1111  1111 1010
  693.                => 
  694.           1111 1111  1111 1111  1111 1101
  695.  
  696.      In contrast, shifting the pattern of bits one place to the right
  697.      with `lsh' looks like this:
  698.  
  699.           (lsh -6 -1)
  700.                => 8388605       ; Decimal -6 becomes decimal 8,388,605.
  701.           
  702.           1111 1111  1111 1111  1111 1010
  703.                => 
  704.           0111 1111  1111 1111  1111 1101
  705.  
  706.      In this case, the 1 in the leftmost position is shifted one
  707.      place to the right, and a zero is shifted into the leftmost
  708.      position.
  709.  
  710.      Here are other examples:
  711.  
  712.                                  ;               24-bit binary values
  713.           
  714.           (lsh 5 2)              ;   5  =  0000 0000  0000 0000  0000 0101
  715.                => 20             ;  20  =  0000 0000  0000 0000  0001 0100
  716.           (ash 5 2)
  717.                => 20
  718.           (lsh -5 2)             ;  -5  =  1111 1111  1111 1111  1111 1011
  719.                => -20            ; -20  =  1111 1111  1111 1111  1110 1100
  720.           (ash -5 2)
  721.                => -20
  722.           
  723.           (lsh 5 -2)             ;   5  =  0000 0000  0000 0000  0000 0101
  724.                => 1              ;   1  =  0000 0000  0000 0000  0000 0001
  725.           (ash 5 -2)
  726.                => 1
  727.           (lsh -5 -2)            ;  -5  =  1111 1111  1111 1111  1111 1011
  728.                => 4194302        ;         0011 1111  1111 1111  1111 1110
  729.           (ash -5 -2)            ;  -5  =  1111 1111  1111 1111  1111 1011
  730.                => -2             ;  -2  =  1111 1111  1111 1111  1111 1110
  731.  
  732.  * Function: logand &rest MARKERS-OR-INTS
  733.      This function returns the "logical and" of the arguments: the
  734.      Nth bit is set in the result if, and only if, the Nth bit is set
  735.      in all the arguments.  ("Set" means that the value of the bit is
  736.      1 rather than 0.)
  737.  
  738.      For example, using 4-bit binary numbers, the "logical and" of 13
  739.      and 12 is 12: 1101 combined with 1100 produces 1100.
  740.  
  741.      In both the binary numbers, the leftmost two bits are set (i.e.,
  742.      they are 1's), so the leftmost two bits of the returned value
  743.      are set.  However, for the rightmost two bits, each is zero in
  744.      at least one of the arguments, so the rightmost two bits of the
  745.      returned value are 0's.
  746.  
  747.      Therefore,
  748.  
  749.           (logand 13 12)
  750.                => 12
  751.  
  752.      If `logand' is not passed any argument, it returns a value of
  753.      -1.  This number is an identity element for `logand' because its
  754.      binary representation consists entirely of ones.  If `logand' is
  755.      passed just one argument, it returns that argument.
  756.  
  757.                                  ;                24-bit binary values
  758.           
  759.           (logand 14 13)         ; 14  =  0000 0000  0000 0000  0000 1110
  760.                                  ; 13  =  0000 0000  0000 0000  0000 1101
  761.                => 12             ; 12  =  0000 0000  0000 0000  0000 1100
  762.           
  763.           (logand 14 13 4)       ; 14  =  0000 0000  0000 0000  0000 1110
  764.                                  ; 13  =  0000 0000  0000 0000  0000 1101
  765.                                  ;  4  =  0000 0000  0000 0000  0000 0100
  766.                => 4              ;  4  =  0000 0000  0000 0000  0000 0100
  767.           
  768.           (logand)
  769.                => -1             ; -1  =  1111 1111  1111 1111  1111 1111
  770.  
  771.  * Function: logior &rest MARKERS-OR-INTS
  772.      This function returns the "inclusive or" of its arguments: the
  773.      Nth bit is set in the result if, and only if, the Nth bit is set
  774.      in at least one of the arguments.  If there are no arguments,
  775.      the result is zero, which is an identity element for this
  776.      operation.  If `logior' is passed just one argument, it returns
  777.      that argument.
  778.  
  779.                                  ;               24-bit binary values
  780.           
  781.           (logior 12 5)          ; 12  =  0000 0000  0000 0000  0000 1100
  782.                                  ;  5  =  0000 0000  0000 0000  0000 0101
  783.                => 13             ; 13  =  0000 0000  0000 0000  0000 1101
  784.           
  785.           (logior 12 5 7)        ; 12  =  0000 0000  0000 0000  0000 1100
  786.                                  ;  5  =  0000 0000  0000 0000  0000 0101
  787.                                  ;  7  =  0000 0000  0000 0000  0000 0111
  788.                => 15             ; 15  =  0000 0000  0000 0000  0000 1111
  789.  
  790.  * Function: logxor &rest MARKERS-OR-INTS
  791.      This function returns the "exclusive or" of its arguments: the
  792.      Nth bit is set in the result if, and only if, the Nth bit is set
  793.      in an odd number of the arguments.  If there are no arguments,
  794.      the result is 0.  If `logxor' is passed just one argument, it
  795.      returns that argument.
  796.  
  797.                                  ;               24-bit binary values
  798.           
  799.           (logxor 12 5)          ; 12  =  0000 0000  0000 0000  0000 1100
  800.                                  ;  5  =  0000 0000  0000 0000  0000 0101
  801.                => 9              ;  9  =  0000 0000  0000 0000  0000 1001
  802.           
  803.           (logxor 12 5 7)        ; 12  =  0000 0000  0000 0000  0000 1100
  804.                                  ;  5  =  0000 0000  0000 0000  0000 0101
  805.                                  ;  7  =  0000 0000  0000 0000  0000 0111
  806.                => 14             ; 14  =  0000 0000  0000 0000  0000 1110
  807.  
  808.  * Function: lognot INTEGER
  809.      This function returns the logical complement of its argument:
  810.      the Nth bit is one in the result if, and only if, the Nth bit is
  811.      zero in INTEGER, and vice-versa.
  812.  
  813.           (lognot 5)             ;  5  =  0000 0000  0000 0000  0000 0101
  814.                => -6             ; -6  =  1111 1111  1111 1111  1111 1010
  815.  
  816.  
  817. 
  818. File: elisp,  Node: Random Numbers,  Prev: Bitwise Operations,  Up: Numbers
  819.  
  820. Random Numbers
  821. ==============
  822.  
  823.  * Function: random &optional FLAG
  824.      This function returns a pseudo-random number of type integer. 
  825.      When called more than once, this function returns a series of
  826.      pseudo-random numbers.
  827.  
  828.      In a computer, a series of a pseudo-random numbers is generated
  829.      in a deterministic fashion.  The numbers are not truly random,
  830.      but they have certain properties that mimic a random series. 
  831.      For example, all possible values occur equally often in a
  832.      pseudo-random series.
  833.  
  834.      In Emacs, pseudo-random numbers are generated from a "seed"
  835.      number.  If the `random' function starts with the same seed, it
  836.      generates the same sequence of numbers.  Emacs always starts
  837.      with the same seed value, so the sequence of values of `random'
  838.      is actually the same in each Emacs run!  For example, in one
  839.      operating system, the first call to `(random)' after you start
  840.      Emacs always returns -1457731, and the second one always returns
  841.      -7692030.  This is helpful for debugging.
  842.  
  843.      If you want different random numbers, execute `(random t)'. 
  844.      This chooses a new seed based on the current time of day and on
  845.      Emacs' process ID number.
  846.  
  847.      On some machines, any integer representable in Lisp may be the
  848.      result of `random'.  On other machines, the result can never be
  849.      larger than a certain maximum or less than a certain (negative)
  850.      minimum.
  851.  
  852.  
  853. 
  854. File: elisp,  Node: Strings and Characters,  Next: Lists,  Prev: Numbers,  Up: Top
  855.  
  856. Strings and Characters
  857. **********************
  858.  
  859.    A string in Emacs Lisp is an array that contains an ordered
  860. sequence of characters.  Strings are used as names of symbols,
  861. buffers, and files, to send messages to users, to hold text being
  862. copied between buffers, and for many other purposes.  Because strings
  863. are so important, many functions are provided expressly for
  864. manipulating them.  Emacs Lisp programs use strings more often than
  865. individual characters.
  866.  
  867. * Menu:
  868.  
  869. * Intro to Strings::          Basic properties of strings and characters.
  870. * Predicates for Strings::    Testing whether an object is a string or char.
  871. * Creating Strings::          Functions to allocate new strings.
  872. * Text Comparison::           Comparing characters or strings.
  873. * String Conversion::         Converting characters or strings and vice versa.
  874. * Formatting Strings::        `format': Emacs's analog of `printf'.
  875. * Character Case::            Case conversion functions.
  876.  
  877.  
  878. 
  879. File: elisp,  Node: Intro to Strings,  Next: Predicates for Strings,  Prev: Strings and Characters,  Up: Strings and Characters
  880.  
  881. Introduction to Strings and Characters
  882. ======================================
  883.  
  884.    Characters are represented in Emacs Lisp as integers; whether an
  885. integer was intended as a character or not is determined only by how
  886. it is used.  Strings in Emacs Lisp are arrays that contain an ordered
  887. sequence of characters.
  888.  
  889.    The length of a string (like any array) is fixed and independent
  890. of the string contents, and cannot be altered.  Strings in Lisp are
  891. *not* terminated by a distinguished character code.  (By contrast,
  892. strings in C are terminated by a character with ASCII code 0.) This
  893. means that any character, including the null character (ASCII code
  894. 0), is a valid element of a string.
  895.  
  896.    Since strings are considered arrays, you can operate on them with
  897. the general array functions.  (*Note Sequences Arrays Vectors::.) 
  898. For example, you can access or change individual characters in a
  899. string using the functions `aref' and `aset' (*note Array
  900. Functions::.).
  901.  
  902.    Each character in a string is stored in a single byte.  Therefore,
  903. numbers not in the range 0 to 255 are truncated when stored into a
  904. string.  This means that a string takes up much less memory than a
  905. vector of the same length.
  906.  
  907.    *Note Text::, for information about functions that display strings
  908. or copy them into buffers.  *Note Character Type::, and *Note String
  909. Type::, for information about the syntax of characters and strings.
  910.  
  911.  
  912. 
  913. File: elisp,  Node: Predicates for Strings,  Next: Creating Strings,  Prev: Intro to Strings,  Up: Strings and Characters
  914.  
  915. The Predicates for Strings
  916. ==========================
  917.  
  918.    For more information about general sequence and array predicates,
  919. see *Note Sequences Arrays Vectors::, and *Note Arrays::.
  920.  
  921.  * Function: stringp OBJECT
  922.      This function returns `t' if OBJECT is a string, `nil' otherwise.
  923.  
  924.  * Function: char-or-string-p OBJECT
  925.      This function returns `t' if OBJECT is a string or a character
  926.      (i.e., an integer), `nil' otherwise.
  927.  
  928.  
  929. 
  930. File: elisp,  Node: Creating Strings,  Next: Text Comparison,  Prev: Predicates for Strings,  Up: Strings and Characters
  931.  
  932. Creating Strings
  933. ================
  934.  
  935.    The following functions create strings, either from scratch, or by
  936. putting strings together, or by taking them apart.
  937.  
  938.  * Function: make-string COUNT CHARACTER
  939.      This function returns a string made up of COUNT repetitions of
  940.      CHARACTER.  If COUNT is negative, an error is signaled.
  941.  
  942.           (make-string 5 ?x)
  943.                => "xxxxx"
  944.           (make-string 0 ?x)
  945.                => ""
  946.  
  947.      Other functions to compare with this one include
  948.      `char-to-string' (*note String Conversion::.), `make-vector'
  949.      (*note Vectors::.), and `make-list' (*note Building Lists::.).
  950.  
  951.  * Function: substring STRING START &optional END
  952.      This function returns a new string which consists of those
  953.      characters from STRING in the range from (and including) the
  954.      character at the index START up to (but excluding) the character
  955.      at the index END.  The first character is at index zero.
  956.  
  957.           (substring "abcdefg" 0 3)
  958.                => "abc"
  959.  
  960.      Here the index for `a' is 0, the index for `b' is 1, and the
  961.      index for `c' is 2.  Thus, three letters, `abc', are copied from
  962.      the full string.  The index 3 marks the character position up to
  963.      which the substring is copied.  The character whose index is 3
  964.      is actually the fourth character in the string.
  965.  
  966.      A negative number counts from the end of the string, so that -1
  967.      signifies the index of the last character of the string.  For
  968.      example:
  969.  
  970.           (substring "abcdefg" -3 -1)
  971.                => "ef"
  972.  
  973.      In this example, the index for `e' is -3, the index for `f' is
  974.      -2, and the index for `g' is -1.  Therefore, `e' and `f' are
  975.      included, and `g' is excluded.
  976.  
  977.      When `nil' is used as an index, it falls after the last
  978.      character in the string.  Thus:
  979.  
  980.           (substring "abcdefg" -3 nil)
  981.                => "efg"
  982.  
  983.      Omitting the argument END is equivalent to specifying `nil'.  It
  984.      follows that `(substring STRING 0)' returns a copy of all of
  985.      STRING.
  986.  
  987.           (substring "abcdefg" 0)
  988.                => "abcdefg"
  989.  
  990.      But we recommend `copy-sequence' for this purpose.
  991.  
  992.      A `wrong-type-argument' error is signaled if either START or END
  993.      are non-integers.  An `args-out-of-range' error is signaled if
  994.      START indicates a character following END, or if either integer
  995.      is out of range for STRING.
  996.  
  997.      Contrast this function with `buffer-substring' (*note Buffer
  998.      Contents::.), which returns a string containing a portion of the
  999.      text in the current buffer.  The beginning of a string is at
  1000.      index 0, but the beginning of a buffer is at index 1.
  1001.  
  1002.  * Function: concat &rest SEQUENCES
  1003.      This function returns a new string consisting of the characters
  1004.      in the arguments passed to it.  The arguments may be strings,
  1005.      lists of numbers, or vectors of numbers; they are not themselves
  1006.      changed.  If no arguments are passed to `concat', it returns an
  1007.      empty string.
  1008.  
  1009.           (concat "abc" "-def")
  1010.                => "abc-def"
  1011.           (concat "abc" (list 120 (+ 256 121)) [122])
  1012.                => "abcxyz"
  1013.           (concat "The " "quick brown " "fox.")
  1014.                => "The quick brown fox."
  1015.           (concat)
  1016.                => ""
  1017.  
  1018.      The second example above shows how characters stored in strings
  1019.      are taken modulo 256.  In other words, each character in the
  1020.      string is stored in one byte.
  1021.  
  1022.      The `concat' function always constructs a new string that is not
  1023.      `eq' to any existing string.
  1024.  
  1025.      When an argument is an integer (not a sequence of integers), it
  1026.      is converted to a string of digits making up the decimal printed
  1027.      representation of the integer.  This special case exists for
  1028.      compatibility with Mocklisp, and we don't recommend you take
  1029.      advantage of it.  If you want to convert an integer in this way,
  1030.      use `format' (*note Formatting Strings::.) or `int-to-string'
  1031.      (*note String Conversion::.).
  1032.  
  1033.           (concat 137)
  1034.                => "137"
  1035.           (concat 54 321)
  1036.                => "54321"
  1037.  
  1038.      For information about other concatenation functions, see
  1039.      `mapconcat' in *Note Mapping Functions::, `vconcat' in *Note
  1040.      Vectors::, and `append' in *Note Building Lists::.
  1041.  
  1042.  
  1043. 
  1044. File: elisp,  Node: Text Comparison,  Next: String Conversion,  Prev: Creating Strings,  Up: Strings and Characters
  1045.  
  1046. Comparison of Characters and Strings
  1047. ====================================
  1048.  
  1049.  * Function: char-equal CHARACTER1 CHARACTER2
  1050.      This function returns `t' if the arguments represent the same
  1051.      character, `nil' otherwise.  This is done by comparing two
  1052.      integers modulo 256.
  1053.  
  1054.           (char-equal ?x ?x)
  1055.                => t
  1056.           (char-to-string (+ 256 ?x))
  1057.                => "x"
  1058.           (char-equal ?x  (+ 256 ?x))
  1059.                => t
  1060.  
  1061.  * Function: string= STRING1 STRING2
  1062.      This function returns `t' if the characters of the two strings
  1063.      match exactly; case is significant.
  1064.  
  1065.           (string= "abc" "abc")
  1066.                => t
  1067.           (string= "abc" "ABC")
  1068.                => nil
  1069.           (string= "ab" "ABC")
  1070.                => nil
  1071.  
  1072.  * Function: string-equal STRING1 STRING2
  1073.      `string-equal' is another name for `string='.
  1074.  
  1075.  * Function: string< STRING1 STRING2
  1076.      This function compares two strings a character at a time.  First
  1077.      it scans both the strings at once to find the first pair of
  1078.      corresponding characters that do not match.  If the lesser
  1079.      character of those two is the character from STRING1, then
  1080.      STRING1 is less, and this function returns `t'.  If the lesser
  1081.      character is the one from STRING2, then STRING1 is greater, and
  1082.      this function returns `nil'.  If the two strings match entirely,
  1083.      the value is `nil'.
  1084.  
  1085.      Pairs of characters are compared by their ASCII codes.  Keep in
  1086.      mind that lower case letters have higher numeric values in the
  1087.      ASCII character set than their upper case counterparts; numbers
  1088.      and many punctuation characters have a lower numeric value than
  1089.      upper case letters.
  1090.  
  1091.           (string< "abc" "abd")
  1092.                => t
  1093.           (string< "abd" "abc")
  1094.                => nil
  1095.           (string< "123" "abc")
  1096.                => t
  1097.  
  1098.      When the strings have different lengths, and they match up to
  1099.      the length of STRING1, then the result is `t'.  If they match up
  1100.      to the length of STRING2, the result is `nil'.  A string without
  1101.      any characters in it is the smallest possible string.
  1102.  
  1103.           (string< "" "abc")
  1104.                => t
  1105.           (string< "ab" "abc")
  1106.                => t
  1107.           (string< "abc" "")
  1108.                => nil
  1109.           (string< "abc" "ab")
  1110.                => nil
  1111.           (string< "" "")
  1112.                => nil
  1113.  
  1114.  * Function: string-lessp STRING1 STRING2
  1115.      `string-lessp' is another name for `string<'.
  1116.  
  1117.  
  1118. 
  1119. File: elisp,  Node: String Conversion,  Next: Formatting Strings,  Prev: Text Comparison,  Up: Strings and Characters
  1120.  
  1121. Conversion of Characters and Strings
  1122. ====================================
  1123.  
  1124.    Characters and strings may be converted into each other and into
  1125. integers.  `format' and `prin1-to-string' (*note Output Functions::.)
  1126. may also be used to convert Lisp objects into strings. 
  1127. `read-from-string' (*note Input Functions::.) may be used to
  1128. "convert" a string representation of a Lisp object into an object.
  1129.  
  1130.    *Note Documentation::, for a description of the functions
  1131. `single-key-description' and `text-char-description', which return a
  1132. string representing the Emacs standard notation of the argument
  1133. character.  These functions are used primarily for printing help
  1134. messages.
  1135.  
  1136.  * Function: char-to-string CHARACTER
  1137.      This function returns a new string with a length of one character.
  1138.      The value of CHARACTER, modulo 256, is used to initialize the
  1139.      element of the string.
  1140.  
  1141.      This function is similar to `make-string' with an integer
  1142.      argument of 1.  (*Note Creating Strings::.)  This conversion can
  1143.      also be done with `format' using the `%c' format specification. 
  1144.      (*Note Formatting Strings::.)
  1145.  
  1146.           (char-to-string ?x)
  1147.                => "x"
  1148.           (char-to-string (+ 256 ?x))
  1149.                => "x"
  1150.           (make-string 1 ?x)
  1151.                => "x"
  1152.  
  1153.  * Function: string-to-char STRING
  1154.      This function returns the first character in STRING.  If the
  1155.      string is empty, the function returns 0.  The value is also 0
  1156.      when the first character of STRING is the null character, ASCII
  1157.      code 0.
  1158.  
  1159.           (string-to-char "ABC")
  1160.                => 65
  1161.           (string-to-char "xyz")
  1162.                => 120
  1163.           (string-to-char "")
  1164.                => 0
  1165.           (string-to-char "\000")
  1166.                => 0
  1167.  
  1168.      This function may be eliminated in version 19 if it does not
  1169.      seem useful enough to retain.
  1170.  
  1171.  * Function: int-to-string INTEGER
  1172.      This function returns a string consisting of the digits of
  1173.      INTEGER, base ten.  When passed a positive integer as an
  1174.      argument, this function returns an unsigned string.  When passed
  1175.      a negative integer, the function returns a string with a leading
  1176.      minus sign.
  1177.  
  1178.           (int-to-string 256)
  1179.                => "256"
  1180.           (int-to-string -23)
  1181.                => "-23"
  1182.  
  1183.      See also the function `format' in *Note Formatting Strings::.
  1184.  
  1185.  * Function: string-to-int STRING
  1186.      This function returns the integer value of the characters in
  1187.      STRING, read as a number in base ten.
  1188.  
  1189.      The string is read starting from (and including) the first
  1190.      character, and it is read until a non-digit is encountered.  If
  1191.      the first character is not a digit or a minus sign, this
  1192.      function returns 0.
  1193.  
  1194.           (string-to-int "256")
  1195.                => 256
  1196.           (string-to-int "25 is a perfect square.")
  1197.                => 25
  1198.           (string-to-int "X256")
  1199.                => 0
  1200.           (string-to-int "-4")
  1201.                => -4
  1202.  
  1203.  
  1204. 
  1205. File: elisp,  Node: Formatting Strings,  Next: Character Case,  Prev: String Conversion,  Up: Strings and Characters
  1206.  
  1207. Formatting Strings
  1208. ==================
  1209.  
  1210.    "Formatting" means constructing a string by substitution of
  1211. computed values at various places in a constant string.  This string
  1212. controls how the other values are printed as well as where they
  1213. appear; it is called a "format string".
  1214.  
  1215.    Formatting is often useful for computing messages to be displayed.
  1216. In fact, the functions `message' and `error' provide the same
  1217. formatting feature described here; they differ from `format' only in
  1218. how they use the result of formatting.
  1219.  
  1220.  * Function: format STRING &rest OBJECTS
  1221.      This function returns a new string that is made by copying
  1222.      STRING and then replacing any format specification  in the copy
  1223.      with encodings of the corresponding OBJECTS.  The arguments
  1224.      OBJECTS are the computed values to be formatted.
  1225.  
  1226.    A format specification is a sequence of characters beginning with
  1227. a `%'.  Thus, if there is a `%d' in STRING, the `format' function
  1228. replaces it with the printed representation of one of the values to
  1229. be formatted (one of the arguments OBJECTS).  For example:
  1230.  
  1231.      (format "The value of fill-column is %d." fill-column)
  1232.           => "The value of fill-column is 72."
  1233.  
  1234.    If STRING contains more than one format specification, the format
  1235. specifications are matched in order with successive values from
  1236. OBJECTS.  Thus, the first format specification in STRING is matched
  1237. with the first such value, the second format specification is matched
  1238. with the second such value, and so on.  Any extra format
  1239. specifications (those for which there are no corresponding values)
  1240. cause unpredictable behavior.  Any extra values to be formatted will
  1241. be ignored.
  1242.  
  1243.    Certain format specifications require values of particular types. 
  1244. However, no error is signaled if the value actually supplied fails to
  1245. have the expected type.  Instead, meaningless text is likely to be
  1246. output.
  1247.  
  1248.    Here is a table of the characters that can follow `%' to make up a
  1249. format specification:
  1250.  
  1251. `s'
  1252.      Replace the specification with the printed representation of the
  1253.      object.  If there is no corresponding object, the empty string
  1254.      is used.
  1255.  
  1256. `o'
  1257.      Replace the specification with the base-eight representation of
  1258.      an integer.
  1259.  
  1260. `d'
  1261.      Replace the specification with the base-ten representation of an
  1262.      integer.
  1263.  
  1264. `x'
  1265.      Replace the specification with the base-sixteen representation
  1266.      of an integer.
  1267.  
  1268. `c'
  1269.      Replace the specification with the character which is the value
  1270.      given.
  1271.  
  1272. `%'
  1273.      A single `%' is placed in the string.  This format specification
  1274.      is unusual in that it does not use a value.  For example,
  1275.      `(format "%% %d" 30)' returns `"% 30"'.
  1276.  
  1277.    Any other format character results in an `Invalid format
  1278. operation' error.
  1279.  
  1280.    Here are several examples:
  1281.  
  1282.      (format "The name of this buffer is %s." (buffer-name))
  1283.           => "The name of this buffer is strings.texi."
  1284.      
  1285.      (format "The buffer object prints as %s." (current-buffer))
  1286.           => "The buffer object prints as #<buffer strings.texi>."
  1287.      
  1288.      (format "The octal value of 18 is %o, and the hex value is %x."
  1289.              18 18)
  1290.           => "The octal value of 18 is 22, and the hex value is 12."
  1291.  
  1292.    All the specification characters allow an optional numeric prefix
  1293. between the `%' and the character.  The optional numeric prefix
  1294. defines the minimum width for the object.  If the printed
  1295. representation of the object contains fewer characters than this,
  1296. then it is padded.  The padding is on the left if the prefix is
  1297. positive (or starts with zero) and on the right if the prefix is
  1298. negative.  The padding character is normally a space, but if the
  1299. numeric prefix starts with a zero, zeros are used for padding.
  1300.  
  1301.      (format "%06d will be padded on the left with zeros" 123)
  1302.           => "000123 will be padded on the left with zeros"
  1303.      
  1304.      (format "%-6d will be padded on the right" 123)
  1305.           => "123    will be padded on the right"
  1306.  
  1307.    No matter what the prefix, nothing in the printed representation
  1308. will be truncated.  This allows the programmer to specify minimum
  1309. spacing without knowing how many characters there are in the object's
  1310. printed representation.
  1311.  
  1312.    In the following three examples, `%7s' specifies a minimum width
  1313. of 7.  In the first case, the string inserted in place of `%7s' has
  1314. only 3 letters, so 4 blank spaces are inserted for padding.  In the
  1315. second case, the string `"specification"' is 13 letters wide but is
  1316. not truncated.  In the third case, the padding is on the right. 
  1317. (This does not work in version 18, but does work in version 19.)
  1318.  
  1319.      (format "The word `%7s' actually has %d letters in it." "foo" 
  1320.              (length "foo"))
  1321.           => "The word `    foo' actually has 3 letters in it."  
  1322.      
  1323.      (format "The word `%7s' actually has %d letters in it."
  1324.              "specification" 
  1325.              (length "specification")) 
  1326.           => "The word `specification' actually has 13 letters in it."  
  1327.      
  1328.      (format "The word `%-7s' actually has %d letters in it." "foo" 
  1329.              (length "foo"))
  1330.           => "The word `foo    ' actually has 3 letters in it."  
  1331.      ;; `%-7s' fails to work in version 18, but does work in version 19.
  1332.      ;; In version 18, padding is not inserted.
  1333.  
  1334.